﻿using System.Linq;
#if !NETCOREAPP
using System.Web;
using System.Web.Mvc;
using System.Web.WebPages;
    using System.Web.Mvc.Html;

#endif

#if NETCOREAPP
using Microsoft.AspNetCore.Mvc.Rendering;
using Kugar.Core.Web;
#endif
using Kugar.Core.ExtMethod;
using Kugar.MVC.MobileUI.WeUI.Helpers;

namespace Kugar.MVC.MobileUI.WeUI.PageControls.PageForm
{
    public class PageForm_TextBox:PageForm_FieldBase
    {
        private string _text = "";
        private string _placeHolder = "";
        private InputBoxType _type = InputBoxType.text;
        private string _pattern = "";
        private bool _isrequired = false;
        private bool _isReadOnly = false;

        public PageForm_TextBox(ViewContext viewContext) : base(viewContext)
        {
            this.Css("weui-cells_textbox");
        }

        public PageForm_TextBox Value(string text)
        {
            _text = text;

            return this;
        }

        public PageForm_TextBox Placeholder(string text)
        {
            _placeHolder = text;

            return this;
        }

        public PageForm_TextBox Required(bool isRequired = true)
        {
            _isrequired = isRequired;

            return this;
        }

        public PageForm_TextBox Type(InputBoxType type)
        {
            _type = type;

            return this;
        }

        public PageForm_TextBox Pattern(string pattern)
        {
            _pattern = pattern;

            return this;
        }

        public PageForm_TextBox Readonly(bool isReadOnly = true)
        {
            _isReadOnly = isReadOnly;

            return this;
        }

        protected override void RenderBody()
        {
            ViewContext.Writer.WriteLine($"<input class=\"weui-input\" name=\"{getName()}\" {_isReadOnly.If("readonly")} {_isrequired.If("required")} value=\"{_text}\" type=\"{_type.ToString()}\" {(string.IsNullOrWhiteSpace(_pattern) ? "" : $"pattern=\"{_pattern}\"")} placeholder=\"{_placeHolder}\">");

        }

    }

    public enum InputBoxType
    {
        text=0,

        number=1
    }
}